package com.example.map.rx1demo.learns;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.example.map.rx1demo.R;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by qundui on 2017/6/5.
 */

public class NetTest extends Activity {
    DownImageUtils downImageUtils;
    String PATH="http://cdnq.duitang.com/uploads/item/201505/20/20150520102944_CiL3M.jpeg";
    ImageView iv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.nettest);
        downImageUtils=new DownImageUtils();
        iv= (ImageView) findViewById(R.id.iv);
    }
    public void downImage(View view){
//        downImageUtils.DownImage(PATH).observeOn(Schedulers.io()).subscribeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<String>() {
//            @Override
//            public void onCompleted() {
//
//            }
//
//            @Override
//            public void onError(Throwable e) {
//
//            }
//
//            @Override
//            public void onNext(String s) {
//
//            }
//        });
//        Picasso.with(this).load(PATH).into(iv);
        downImageUtils.DownImage(PATH).observeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<byte[]>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(byte[] inputStream) {
                Bitmap bitmap =BitmapFactory.decodeByteArray(inputStream,0,inputStream.length);

                iv.setImageBitmap(bitmap);

            }
        });


    }
}
